﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import Engine.Classes.*;
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Transactions.*;
    import Classes.util.*;
    import Classes.sim.*;
    import __AS3__.vec.*;
    import Classes.effects.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import Modules.bandits.*;
    import Modules.quest.Managers.*;
    import Display.*;
    import Display.FactoryUI.*;
    import Modules.franchise.display.*;
    import Display.UpgradesUI.*;
    import GameMode.*;
    import Classes.doobers.*;
    import flash.text.*;
    import Classes.actions.*;
    import Classes.inventory.*;
    import Modules.franchise.data.*;
    import Modules.guide.ui.*;
    import Modules.stats.experiments.*;
    import Display.aswingui.*;
    import Display.PopulationUI.*;
    import Modules.stats.types.*;
    import com.zynga.skelly.util.*;
    import Modules.quest.Helpers.*;
    import Modules.franchise.transactions.*;

    public class Business extends HarvestableResource implements ICustomToolTipTarget, IPlayerStateObserver, IMerchant {

        public static const STATE_CLOSED:String = "closed";
        public static const STATE_CLOSED_HARVESTABLE:String = "closedHarvestable";
        public static const STATE_OPEN:String = "open";
        public static const STATE_OPEN_HARVESTABLE:String = "openHarvestable";
        public static const UPGRADE_FLOATER_GLOW:GlowFilter = new GlowFilter(0x202020, 0.8, 1.5, 1.5, 50, BitmapFilterQuality.HIGH);
        public static const DEFAULT_BUSINESS_IMAGE:String = "static";
        public static const DELIVERY_VEHICLE:String = "van_delivery";
        public static const TOUR_BUS:String = "tourismbus";
        public static const HAMMER_PICK_FADE_MULTIPLIER:Number = 5;
        public static const UPGRADE_PICK_FADE_MULTIPLIER:Number = 5;
        public static const UPGRADES_FLAG_INTRO:String = "biz_ups_intro";
        public static const UPGRADES_FLAG_HALFWAY:String = "biz_ups_halfway";
        public static const UPGRADE_QUEST_NAME:String = "qm_upgrade_business";

        private static var intTourBusNPCCount:int = 0;

        private const BUSINESS:String = "business";
        private const DESIRED_COMMODITY:String = "premium_goods";

        protected var m_crowdManager:MerchantCrowdManager;
        protected var m_visits:int;
        protected var m_pick:SlidePick;
        protected var m_shockwaveActive:Boolean;
        private var m_shockwaveComplete:Boolean = false;
        protected var m_tourBus:TourBus;
        protected var m_itemName:String;
        protected var m_ugcName:String;
        private var needRibbons:Boolean = false;
        private var gotRibbons:Boolean = false;
        private var m_headquartersName:String;
        protected var m_isDelivering:Boolean = false;
        protected var m_cooldownStart:int;
        protected var m_neverOpened:Boolean = true;
        private var m_noShockwaveHits:Boolean = false;
        protected var m_friendFranchiseData:FriendFranchiseData;
        protected var m_friendFranchiseName:String;
        private var originalUGCText:String;
        private var m_futureVisits:int = 0;
        private var m_grandOpeningActive:Boolean = false;
        private var m_customToolTipHeader:JPanel;
        private var m_customToolTipStatus:JPanel;
        private var m_customToolTipStatusLabel:JLabel;
        private var m_customToolTipStatusIcon:AssetPane;
        private var m_starRatingComponent:StarRatingComponent;
        private var m_photoComponent:FranchisePhotoComponent;
        protected var m_upgradeDialog:BusinessUpgradesDialog;
        protected var m_coinPickEffect:CoinPickEffect;

        public function Business(_arg1:String=null){
            this.m_itemName = _arg1;
            this.m_crowdManager = new MerchantCrowdManager(this, this.m_itemName);
            super(this.m_itemName);
            m_objectType = WorldObjectTypes.BUSINESS;
            m_typeName = this.BUSINESS;
            this.m_headquartersName = this.getHeadquartersName();
            this.m_shockwaveActive = false;
            m_isRoadVerifiable = true;
            this.m_neverOpened = true;
            setState(STATE_CLOSED);
            Global.player.addObserver(this);
        }
        public static function decrementBusCounter():void{
            if (intTourBusNPCCount > 0){
                intTourBusNPCCount--;
            };
            if (intTourBusNPCCount == 0){
                Sounds.stop("tourbus_engine_loop");
            };
        }
        public static function refreshAll(_arg1:Array=null):void{
            var _local2:Array;
            var _local3:WorldObject;
            var _local4:MapResource;
            if (_arg1){
                _local2 = Global.world.getObjectsByNames(_arg1);
            } else {
                _local2 = Global.world.getObjectsByClass(Business);
            };
            for each (_local3 in _local2) {
                _local4 = (_local3 as MapResource);
                if (_local4 != null){
                    _local4.setState(_local4.getState());
                    _local4.refreshArrow();
                };
            };
        }

        override public function cleanUp():void{
            this.cleanupCrowd();
            this.cleanupPick();
            if (this.m_coinPickEffect){
                this.m_coinPickEffect.cleanUp();
            };
            if (m_stagePickEffect){
                m_stagePickEffect.cleanUp();
            };
            super.cleanUp();
        }
        override protected function statsInit():void{
            super.statsInit();
            if (this.isFranchise()){
                m_statsName = "franchise";
            };
            registerStatsActionName(TrackedActionType.FIRST_PLANT, "grandopening");
            registerStatsActionName(TrackedActionType.HARVEST, "collect");
            registerStatsActionName(TrackedActionType.PLANT, "open");
        }
        override public function trackDetailedAction(_arg1:String, _arg2:String, _arg3:String, _arg4:int=1):void{
            if (this.isFranchise()){
                StatsManager.social(StatsKingdomType.GAME_ACTIONS, this.getBusinessOwner(), m_statsName, getStatsActionName(_arg1), m_statsItemName, _arg2, _arg4);
            } else {
                super.trackDetailedAction(_arg1, _arg2, _arg3, _arg4);
            };
        }
        public function get headquartersName():String{
            return (this.m_headquartersName);
        }
        private function getHeadquartersName():String{
            return (getItem().xml.headquarters);
        }
        public function cleanupCrowd():void{
            if (this.m_crowdManager){
                this.m_crowdManager.cleanup();
                this.m_crowdManager = null;
            };
        }
        public function cleanupPick():void{
            if (this.m_pick){
                if (this.m_pick.parent != null){
                    this.m_pick.parent.removeChild(this.m_pick);
                };
                this.m_pick.cleanUp();
                this.m_pick = null;
            };
        }
        public function get crowdManager():MerchantCrowdManager{
            return (this.m_crowdManager);
        }
        public function get commodityQty():int{
            return (Global.gameSettings.getInt("npcCommodityConsumption", 1));
        }
        public function get maxVisits():int{
            return (harvestingDefinition.commodityReq);
        }
        public function isRouteable():Boolean{
            var _local1:Boolean;
            if (((((this.isOpen()) && (!(isNeedingRoad)))) && ((this.getPopularity() > 0)))){
                _local1 = true;
            };
            return (_local1);
        }
        public function hasHotspot():Boolean{
            var _local1:Boolean;
            if (null != getHotspot()){
                _local1 = true;
            };
            return (_local1);
        }
        public function getPopularity():int{
            return (this.npcPopularity);
        }
        public function setPopularity(_arg1:int):void{
            this.npcPopularity = _arg1;
        }
        override protected function getCurrentImage():ItemImageInstance{
            var _local1:ItemImageInstance = m_item.getCachedImage(DEFAULT_BUSINESS_IMAGE, this, m_direction, m_statePhase);
            return (_local1);
        }
        override public function isCurrentImageLoading():Boolean{
            return (m_item.isCachedImageLoading(DEFAULT_BUSINESS_IMAGE, m_direction, m_statePhase));
        }
        override public function isDrawImageLoading():Boolean{
            if (m_item == null){
                return (false);
            };
            return (m_item.isCachedImageLoading(DEFAULT_BUSINESS_IMAGE, m_direction, m_statePhase));
        }
        override protected function computeDefaultHotspots():Vector.<Vector3>{
            var _local1:Vector.<Vector3> = m_item.getCachedImageHotspots(DEFAULT_BUSINESS_IMAGE, m_direction);
            return (((_local1)!=null) ? _local1 : super.computeDefaultHotspots());
        }
        public function get franchiseType():String{
            var _local1:String = Item.findUpgradeRoot(this.getItem());
            return (((_local1)!=null) ? _local1 : this.m_itemName);
        }
        private function isFranchiseSupplied():Boolean{
            return (((this.m_friendFranchiseData) && ((this.m_friendFranchiseData.commodityLeft > 0))));
        }
        public function getFranchiseName():String{
            var _local1:String = Global.franchiseManager.model.getDefaultFranchiseName(this.franchiseType, this.getBusinessOwner());
            var _local2:FranchiseDataModel = Global.franchiseManager.getDataModel(this.getBusinessOwner());
            if (_local2){
                _local1 = _local2.getFranchiseName(this.franchiseType);
            } else {
                if (this.m_friendFranchiseData != null){
                    _local1 = ((this.m_friendFranchiseData.franchiseName) || (_local1));
                };
            };
            return (_local1);
        }
        public function getStarRating():Number{
            var _local3:FranchiseExpansionData;
            var _local1:Number = 0;
            var _local2:FranchiseDataModel = Global.franchiseManager.getDataModel(this.getBusinessOwner());
            if (_local2){
                _local3 = _local2.getFranchise(this.franchiseType, Global.world.ownerId);
                if (_local3){
                    _local1 = _local3.starRating;
                };
            } else {
                _local1 = this.m_friendFranchiseData.starRating;
            };
            return (_local1);
        }
        override protected function getSellPrice():int{
            if (!this.isFranchise()){
                return (m_item.sellPrice);
            };
            return (0);
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
            this.m_visits = int(_arg1.visits);
            this.m_neverOpened = Boolean(_arg1.neverOpened);
            if ((((m_state == STATE_OPEN)) || ((m_state == STATE_OPEN_HARVESTABLE)))){
                this.activatePeepSpawning();
            };
            if (((_arg1) && (_arg1["franchise_info"]))){
                this.m_friendFranchiseData = FriendFranchiseData.loadObject(_arg1["franchise_info"]);
            };
            this.updateSlidePickText();
            setState(getState());
        }
        override public function initFriendData(_arg1:String):void{
            this.m_friendFranchiseData = new FriendFranchiseData(0, _arg1, 1);
            setState(STATE_CLOSED);
            this.m_isDragged = false;
            this.calculateDepthIndex();
            this.conditionallyReattach(true);
        }
        override public function drawDisplayObject():void{
            super.drawDisplayObject();
            this.gotRibbons = false;
            this.updateRibbons();
        }
        override public function onObjectDrop(_arg1:Vector3):void{
            this.reloadImage();
            super.onObjectDrop(_arg1);
            this.verifySpawning(m_state, m_state);
            this.createCoinPickEffect();
            this.createStagePickEffect();
            if (!isNeedingRoad){
                this.displayStatus(ZLoc.t("Main", "ConnectedToRoad"), "", 0xAA00);
            };
        }
        override public function reloadImage():void{
            super.reloadImage();
        }
        override public function replaceContent(_arg1:DisplayObject):void{
            super.replaceContent(_arg1);
            this.updateEffects();
        }
        override public function updateRoadState():void{
            super.updateRoadState();
            this.verifySpawning(m_state, m_state);
            this.updateEffects();
        }
        private function updateEffects():void{
            if (((!(isNeedingRoad)) && (!(this.isUxLockedByQuests)))){
                m_arrow = this.createSigns();
                this.updateRibbons();
                this.createCoinPickEffect();
                this.createStagePickEffect();
            } else {
                removeAnimatedEffects();
                if (m_arrow){
                    m_arrow = null;
                };
                if (this.m_coinPickEffect){
                    this.m_coinPickEffect.cleanUp();
                    this.m_coinPickEffect = null;
                };
                removeStagePickEffect();
            };
        }
        override protected function updateState(_arg1:Number):Boolean{
            var _local2:String = getState();
            return (!((_local2 == m_state)));
        }
        public function isFranchise():Boolean{
            return (((itemOwner) && (!((itemOwner == Global.world.ownerId)))));
        }
        public function isNeverOpened():Boolean{
            return (this.m_neverOpened);
        }
        public function isNewFranchise():Boolean{
            return (((this.isFranchise()) && (this.isNeverOpened())));
        }
        public function updatePeepSpawning():void{
            this.verifySpawning(m_state, m_state);
        }
        public function verifySpawning(_arg1:String, _arg2:String):void{
            var _local7:String;
            var _local3:Boolean = (((_arg1 == STATE_OPEN)) || ((_arg1 == STATE_OPEN_HARVESTABLE)));
            var _local4:Boolean = (((_arg1 == STATE_CLOSED)) || ((_arg1 == STATE_CLOSED_HARVESTABLE)));
            var _local5:Boolean = (((_arg2 == STATE_CLOSED)) || ((_arg2 == STATE_CLOSED_HARVESTABLE)));
            var _local6:Boolean = (((_arg2 == STATE_OPEN)) || ((_arg2 == STATE_OPEN_HARVESTABLE)));
            if (((_local6) && (!(isNeedingRoad)))){
                this.activatePeepSpawning();
            };
            if ((((((_arg2 == STATE_OPEN)) && (_local4))) && (!(isNeedingRoad)))){
                this.m_isDelivering = false;
                _local7 = this.DESIRED_COMMODITY;
                addSupply(_local7, harvestingDefinition.commodityReq);
                GameTransactionManager.addTransaction(new TOpenBusiness(this, _local7));
                if (this.canCountUpgradeActions()){
                    if (!Global.player.getSeenFlag(UPGRADES_FLAG_INTRO)){
                        Global.player.setSeenFlag(UPGRADES_FLAG_INTRO);
                        Business.refreshAll(["bus_bakery", "bus_bakery_2", "bus_bakery_3"]);
                        if (!Global.questManager.hasSeenQuestIntro(UPGRADE_QUEST_NAME)){
                            Global.questManager.pumpActivePopup(UPGRADE_QUEST_NAME);
                        };
                    };
                    this.incrementUpgradeActionCount();
                    setShowUpgradeArrow(true);
                };
                if (this.isNeverOpened()){
                    this.doGrandOpeningAnimation();
                    trackAction(TrackedActionType.FIRST_PLANT);
                };
            };
            if (((_local5) || (isNeedingRoad))){
                this.crowdManager.stopCollecting();
            };
            if (((((_local5) && (_local3))) || (isNeedingRoad))){
                Global.world.citySim.npcManager.onBusinessClosed();
            };
        }
        override protected function onStateChanged(_arg1:String, _arg2:String):void{
            super.onStateChanged(_arg1, _arg2);
            if (isAttached()){
                this.showGrandOpening();
            };
            this.verifySpawning(_arg1, _arg2);
        }
        override public function attach():void{
            super.attach();
            this.showGrandOpening();
        }
        public function activatePeepSpawning():void{
            Global.world.citySim.npcManager.startSpawningBusinessPeeps();
            this.crowdManager.startCollecting();
        }
        override public function onBuildingConstructionCompleted_PreServerUpdate():void{
            var _local2:String;
            var _local3:OwnedFranchiseData;
            var _local1:OwnedFranchiseData = Global.franchiseManager.getFranchise(m_item.name);
            if (_local1){
                _local2 = _local1.franchiseName;
            };
            if ((((((((this.getBusinessCount() == 1)) && (!(Global.isVisiting())))) && (!(this.isFranchise())))) && ((_local2 == null)))){
                this.createNameDialog();
                _local3 = new OwnedFranchiseData(m_item.name, null, null, new Dictionary(), 0);
                Global.franchiseManager.model.addOwnedFranchise(_local3);
            } else {
                this.showGrandOpening();
            };
        }
        private function getBusinessCount():int{
            var _local3:Business;
            var _local1:int;
            var _local2:Array = Global.world.getObjectsByNames([this.franchiseType]);
            for each (_local3 in _local2) {
                if (!_local3.isFranchise()){
                    _local1++;
                };
            };
            return (_local1);
        }
        protected function createCelebrationCrowd():void{
            if (!Global.isVisiting()){
                if (!Global.world.citySim.roadManager.getRoadSize()){
                    Global.world.citySim.roadManager.onGameLoaded(null);
                };
                if (((((this.isFranchiseSupplied()) && (Global.world.citySim.roadManager.getRoadSize()))) && (!(this.m_grandOpeningActive)))){
                    Global.world.citySim.npcManager.createFranchiseFreebiePeeps(this, 4);
                    this.m_grandOpeningActive = true;
                };
            };
        }
        protected function createNameDialog():void{
            var _local1:String = ZLoc.t("Dialogs", "rename_business_message", {item:ZLoc.t("Items", (this.m_itemName + "_friendlyName"))});
            var _local2:String = ZLoc.t("Dialogs", "rename_business_inputLabel", {item:ZLoc.t("Items", (this.m_itemName + "_friendlyName"))});
            var _local3:String = Global.franchiseManager.model.getFranchiseName(this.franchiseType);
            this.m_ugcName = _local3;
            this.originalUGCText = this.m_ugcName;
            var _local4:InputTextDialog = new InputTextDialog(_local1, "rename_business", _local2, _local3, Global.gameSettings.getInt("maxBusinessNameLength", 15), GenericDialogView.TYPE_SAVESHARECOINS, this.onNameDialogComplete, true, this.onNameDialogSkip);
            if (Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_CTTC_TEXT_INPUT_GATE) == ExperimentDefinitions.CTTC_TEXT_INPUT_OPEN){
                _local4.textField.addEventListener(Event.CHANGE, this.onNameDialogChange);
            } else {
                _local4.textField.type = TextFieldType.DYNAMIC;
            };
            UI.displayPopup(_local4);
        }
        public function getBusinessOwner():String{
            var _local1:String = m_itemOwner;
            if (!_local1){
                _local1 = Global.world.ownerId;
            };
            return (_local1);
        }
        protected function onNameDialogChange(_arg1:Event):void{
            var _local3:String;
            var _local2:TextField = (_arg1.target as TextField);
            if (_local2){
                _local3 = _local2.text;
                this.m_ugcName = _local3;
            };
        }
        protected function onNameDialogComplete(_arg1:GenericPopupEvent):void{
            Global.franchiseManager.model.setFranchiseName(this.m_ugcName, this.franchiseType);
            GameTransactionManager.addTransaction(new TUpdateFranchiseName(this.franchiseType, this.m_ugcName));
            if (_arg1.button == GenericDialogView.YES){
                Global.world.viralMgr.sendUGCViralFeed(Global.player, Global.player.cityName, ZLoc.t("Items", (this.franchiseType + "_friendlyName")), this.m_ugcName);
            };
            this.showGrandOpening();
        }
        protected function onNameDialogSkip(_arg1:GenericPopupEvent):void{
            Global.franchiseManager.model.setFranchiseName(this.m_ugcName, this.franchiseType);
            GameTransactionManager.addTransaction(new TUpdateFranchiseName(this.franchiseType, this.m_ugcName));
            this.showGrandOpening();
        }
        protected function showGrandOpening():void{
            this.createCelebrationCrowd();
            this.updateRibbons();
            this.updateArrow();
        }
        protected function doGrandOpeningAnimation():void{
            removeAnimatedEffects();
            addAnimatedEffect(EffectType.CELEBRATION_BALLOONS);
            Sounds.playFromSet(Sounds.SET_FANFARE);
            this.needRibbons = false;
            this.m_neverOpened = false;
        }
        override public function onMouseOver(_arg1:MouseEvent):void{
            super.onMouseOver(_arg1);
            if (((((((((!(Global.isVisiting())) && (!(Global.world.isEditMode)))) && (!(this.isInCooldown)))) && (this.isFranchiseSupplied()))) && (!(this.m_shockwaveActive)))){
                this.m_crowdManager.startWavePreview();
            };
        }
        override public function get isHighlightable():Boolean{
            return (((super.isHighlightable) && (((((!((m_state == STATE_OPEN))) || (Global.world.isEditMode))) || ((((m_state == STATE_OPEN)) && (((((this.isUpgradePossible()) || (this.canCountUpgradeActions()))) && (this.canShowUpgradeToolTips())))))))));
        }
        private function checkIfCanSupplyPremiumGoods():Boolean{
            if (!acceptsAsSupplies(Commodities.PREMIUM_GOODS_COMMODITY)){
                return (false);
            };
            if (Global.isVisiting()){
                return (false);
            };
            if (Global.player.commodities.getCount(Commodities.PREMIUM_GOODS_COMMODITY) > 0){
                return (true);
            };
            return (false);
        }
        override public function getCursor():Class{
            var _local1:Class = super.getCursor();
            if (isNeedingRoad){
                _local1 = EmbeddedArt.hud_act_move;
            } else {
                if (m_state == STATE_CLOSED){
                    if (this.checkIfCanSupplyPremiumGoods()){
                        _local1 = EmbeddedArt.hud_biz_premiumsupply;
                    } else {
                        _local1 = EmbeddedArt.hud_biz_supply;
                    };
                };
            };
            return (_local1);
        }
        override public function getCustomCursor():Object{
            var _local2:ASFont;
            var _local3:GlowFilter;
            var _local4:MarginBackground;
            if (this.m_isDelivering){
                return (null);
            };
            if (!m_customCursor){
                m_customCursor = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                m_customCursorLabel = new JLabel("");
                m_customCursorHolder = new Sprite();
                Global.ui.addChild(m_customCursorHolder);
                m_customCursorWindow = new JWindow(m_customCursorHolder);
                _local2 = ASwingHelper.getBoldFont(16);
                _local3 = new GlowFilter(0, 1, 1.2, 1.2, 20, BitmapFilterQuality.HIGH);
                m_customCursorLabel.setForeground(new ASColor(0xFFFFFF));
                m_customCursorLabel.setFont(_local2);
                m_customCursorLabel.setTextFilters([_local3]);
            };
            var _local1:DisplayObject;
            if (isNeedingRoad){
                _local1 = (new EmbeddedArt.hud_act_move() as DisplayObject);
                m_customCursorLabel.setText("");
            } else {
                if (this.isFranchiseSupplied()){
                    _local1 = (new EmbeddedArt.hud_sale_cursor() as DisplayObject);
                    m_customCursorLabel.setText("");
                } else {
                    if (m_state == STATE_CLOSED){
                        _local1 = (new EmbeddedArt.hud_biz_supply() as DisplayObject);
                        m_customCursorLabel.setText("");
                    } else {
                        return (null);
                    };
                };
            };
            if (_local1){
                _local4 = new MarginBackground(_local1, new Insets(0, 0, 0, 0));
                m_customCursor.setBackgroundDecorator(_local4);
                m_customCursor.setPreferredSize(new IntDimension(_local1.width, _local1.height));
                m_customCursor.setMinimumSize(new IntDimension(_local1.width, _local1.height));
                m_customCursor.setMaximumSize(new IntDimension(_local1.width, _local1.height));
            };
            m_customCursor.append(m_customCursorLabel);
            m_customCursorWindow.setContentPane(m_customCursor);
            ASwingHelper.prepare(m_customCursorWindow);
            m_customCursorWindow.show();
            return (m_customCursorWindow);
        }
        override protected function getGrownCursor():Class{
            return (EmbeddedArt.hud_act_openBusiness);
        }
        override protected function getWitheredCursor():Class{
            return (EmbeddedArt.hud_act_clean);
        }
        override public function onMouseOut():void{
            super.onMouseOut();
            if (this.m_crowdManager){
                this.m_crowdManager.endWavePreview();
            };
        }
        override protected function get isUxLockedByQuests():Boolean{
            return (((!((Global.questManager == null))) && (!(Global.questManager.isUXUnlocked(GameQuestManager.QUEST_UX_BIZ_UNLOCKED)))));
        }
        override public function getHighlightColor():uint{
            var _local1:Boolean = ((this.isHarvestable()) && ((Global.world.getTopGameMode() is GMPlay)));
            var _local2:Boolean = ((((((((((this.isUpgradePossible()) || (this.canCountUpgradeActions()))) && (this.canShowUpgradeToolTips()))) && ((Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_BUSINESS_UPGRADES) > 0)))) && (this.isOpen()))) && ((Global.world.getTopGameMode() is GMPlay)));
            return ((_local2) ? EmbeddedArt.UPGRADE_HIGHLIGHT_COLOR : (_local1) ? EmbeddedArt.READY_HIGHLIGHT_COLOR : super.getHighlightColor());
        }
        override protected function updateArrow():void{
            super.updateArrow();
            if (((isNeedingRoad) || (this.isUxLockedByQuests))){
                m_arrow = null;
                if (this.m_coinPickEffect){
                    this.m_coinPickEffect.cleanUp();
                    this.m_coinPickEffect = null;
                };
                removeStagePickEffect();
                return;
            };
            if (((!(Global.isVisiting())) && (hasValidId()))){
                this.createCoinPickEffect();
                this.createStagePickEffect();
                m_arrow = this.createSigns();
            };
            this.reloadImage();
            if (Global.isVisiting()){
                return;
            };
        }
        protected function createSigns():Sprite{
            var _local1:Sprite = new Sprite();
            var _local2:DisplayObject = (new EmbeddedArt.sale_sign() as DisplayObject);
            _local2.visible = false;
            if (this.isFranchiseSupplied()){
                _local2.visible = true;
                removeStagePickEffect();
            };
            _local1.addChild(_local2);
            var _local3:IsoRect = IsoRect.getIsoRectFromSize(this.getSize());
            _local2.x = (_local3.bottom.x - (_local2.width / 2));
            _local2.y = (_local3.top.y + (_local2.height / 2));
            return (_local1);
        }
        protected function createCoinPickEffect():void{
            if (!this.m_coinPickEffect){
                this.m_coinPickEffect = (MapResourceEffectFactory.createEffect(this, EffectType.COIN_PICK) as CoinPickEffect);
                this.m_coinPickEffect.setPickType(CoinPickEffect.PICK_1);
            } else {
                this.m_coinPickEffect.setPickType(CoinPickEffect.PICK_1);
                this.m_coinPickEffect.reattach();
            };
        }
        override protected function createStagePickEffect():void{
            var _local1:String = StagePickEffect.PICK_4;
            var _local2:String;
            if (((((((!(_local1)) || (isNeedingRoad))) || (this.isFranchiseSupplied()))) || (this.isUxLockedByQuests))){
                return;
            };
            if (Global.isVisiting()){
                _local1 = StagePickEffect.PICK_TOURBUS;
            } else {
                if (m_state == STATE_CLOSED){
                    _local1 = StagePickEffect.PICK_GOODS;
                } else {
                    if ((((((((m_state == STATE_OPEN)) || ((m_state == STATE_OPEN_HARVESTABLE)))) && (getShowUpgradeArrow()))) && (this.canShowUpgradeToolTips()))){
                        if (this.isUpgradePossible()){
                            _local1 = StagePickEffect.PICK_UPGRADE_HAMMER;
                        } else {
                            if (this.canCountUpgradeActions()){
                                _local1 = StagePickEffect.PICK_UPGRADE;
                            };
                        };
                    };
                };
            };
            var _local3:Boolean;
            if ((((((((((_local1 == StagePickEffect.PICK_TOURBUS)) || ((_local1 == StagePickEffect.PICK_GOODS)))) || ((_local1 == StagePickEffect.PICK_UPGRADE_HAMMER)))) || ((_local1 == StagePickEffect.PICK_UPGRADE)))) || ((m_state == STATE_CLOSED_HARVESTABLE)))){
                _local3 = true;
            };
            if (_local3){
                if (!m_stagePickEffect){
                    m_stagePickEffect = (MapResourceEffectFactory.createEffect(this, EffectType.MASTERY_STAGE_PICK) as StagePickEffect);
                    m_stagePickEffect.setPickType(_local1, _local2);
                    m_stagePickEffect.queuedFloat();
                } else {
                    m_stagePickEffect.setPickType(_local1, _local2);
                    m_stagePickEffect.reattach();
                    m_stagePickEffect.queuedFloat();
                };
                if (_local1 == StagePickEffect.PICK_UPGRADE_HAMMER){
                    m_stagePickEffect.setFadeTime((HAMMER_PICK_FADE_MULTIPLIER * Global.gameSettings.getInt("businessUpgradesExclamationFadeDelay", 1)));
                } else {
                    if (_local1 == StagePickEffect.PICK_UPGRADE){
                        m_stagePickEffect.setFadeTime((UPGRADE_PICK_FADE_MULTIPLIER * Global.gameSettings.getInt("businessUpgradesExclamationFadeDelay", 1)));
                    };
                };
            };
        }
        public function performVisitAnimation(_arg1:Peep):void{
            if (!isNeedingRoad){
                this.createCoinPickEffect();
                this.m_coinPickEffect.setBounceType(_arg1.getBusinessEntranceEffects(this));
                this.m_coinPickEffect.bounceToType(CoinPickEffect.PICK_1);
                this.createStagePickEffect();
                if (m_stagePickEffect){
                    m_stagePickEffect.shine();
                };
            };
        }
        override protected function setArrowPosition():void{
        }
        public function updateSlidePickText():void{
            if (this.m_pick == null){
                return;
            };
        }
        public function addFactoryBoost():void{
        }
        override public function isHarvestable():Boolean{
            if (this.isFranchiseSupplied()){
                return (true);
            };
            return ((((m_state == STATE_OPEN_HARVESTABLE)) || ((m_state == STATE_CLOSED_HARVESTABLE))));
        }
        public function get isInCooldown():Boolean{
            return (!((this.m_cooldownStart == 0)));
        }
        public function isOpen():Boolean{
            return ((((m_state == STATE_OPEN)) || ((m_state == STATE_OPEN_HARVESTABLE))));
        }
        override public function getToolTipComponentList():Array{
            var _local1:Component = buildToolTipComponent(ToolTipDialog.ACTION, (this.getToolTipAction()) ? TextFieldUtil.formatSmallCapsString(this.getToolTipAction()) : null);
            return ([_local1, (_local1) ? ASwingHelper.verticalStrut(-4) : null, this.getCustomToolTipStatus(), this.getCustomToolTipStarComponent(), this.getCustomToolTipLevelBar()]);
        }
        override public function getCustomToolTipStatus():Component{
            if (((this.m_clearLock) || (this.isFranchiseSupplied()))){
                return (null);
            };
            return (buildToolTipComponent(ToolTipDialog.STATUS, this.getToolTipStatus()));
        }
        override public function getCustomToolTipImage():Component{
            if (this.isFranchise()){
                if (!this.m_photoComponent){
                    this.m_photoComponent = new FranchisePhotoComponent(this.getBusinessOwner());
                };
                return (this.m_photoComponent);
            };
            return (null);
        }
        override public function getCustomToolTipLevelBar():Component{
            var _local1:Component;
            if (((((((((!(m_isHarvesting)) && (!(this.m_isDelivering)))) && ((m_clearLock == 0)))) && (this.canShowUpgradeToolTips()))) && (!(this.isUpgradePossible())))){
                _local1 = super.getCustomToolTipLevelBar();
            };
            if (((Global.isVisiting()) && ((_local1 is SimpleProgressBar)))){
                (_local1 as SimpleProgressBar).setProgressRatioText(" ");
            };
            return (_local1);
        }
        public function getCustomToolTipStarComponent():Component{
            if (!this.isFranchise()){
                return (null);
            };
            var _local1:FranchiseExpansionData = Global.franchiseManager.worldOwnerModel.getFranchise(this.franchiseType, this.getBusinessOwner());
            if (((!(_local1)) && (Global.world.isOwnerCitySam))){
                return (null);
            };
            var _local2:Number = this.m_friendFranchiseData.starRating;
            if (!this.m_starRatingComponent){
                this.m_starRatingComponent = new StarRatingComponent(_local2);
            };
            this.m_starRatingComponent.setStarRating(_local2);
            return (this.m_starRatingComponent);
        }
        override public function getToolTipHeader():String{
            return (this.getFranchiseName());
        }
        override public function getToolTipStatus():String{
            var _local2:String;
            var _local1:String;
            if (isNeedingRoad){
                _local1 = ZLoc.t("Dialogs", "NotConnectedToRoad");
                return (_local1);
            };
            if (Global.isVisiting()){
                if (this.m_clearLock){
                    return (_local1);
                };
                if (Global.player.checkVisitorEnergy(1)){
                    _local1 = ZLoc.t("Main", "ClickToSendTour");
                } else {
                    _local1 = ZLoc.t("Main", "NeedEnergy", {amount:1});
                };
            } else {
                if (((this.isFranchise()) && (this.isFranchiseSupplied()))){
                    _local2 = Global.player.getFriendFirstName(m_itemOwner);
                    if (!_local2){
                        _local2 = ZLoc.t("Dialogs", "DefaultFriendName");
                    };
                    _local1 = ZLoc.t("Main", "BusinessSaleStatus", {name:ZLoc.tn(_local2)});
                } else {
                    if (this.m_visits > 0){
                        if ((((m_state == STATE_OPEN)) || ((m_state == STATE_CLOSED_HARVESTABLE)))){
                            _local1 = ZLoc.t("Main", "BusinessCustomers", {
                                served:this.m_visits,
                                max:this.maxVisits
                            });
                        };
                    } else {
                        if (this.m_visits == 0){
                            if (m_state == STATE_OPEN){
                                _local1 = ZLoc.t("Main", "BusinessCustomers", {
                                    served:this.m_visits,
                                    max:this.maxVisits
                                });
                            } else {
                                if (this.m_isDelivering){
                                    _local1 = null;
                                } else {
                                    _local1 = ZLoc.t("Main", "NeedCommodityToOpenAmount", {amount:harvestingDefinition.commodityReq});
                                };
                            };
                        };
                    };
                };
            };
            return (_local1);
        }
        override public function getToolTipAction():String{
            var _local1:String = getGameModeToolTipAction();
            if (!_local1){
                if (isNeedingRoad){
                    return (_local1);
                };
                if (!Global.isVisiting()){
                    if (((this.isFranchise()) && (this.isFranchiseSupplied()))){
                        _local1 = ZLoc.t("Main", "BusinessSaleCTA");
                    } else {
                        if (((((!(isLocked())) && (!(Global.world.isEditMode)))) && (!(this.m_shockwaveActive)))){
                            switch (m_state){
                                case STATE_CLOSED:
                                    if (Global.player.commodities.getAddedCount(commodities) >= harvestingDefinition.commodityReq){
                                        _local1 = ZLoc.t("Main", "ClickToSupply");
                                    } else {
                                        _local1 = Commodities.getNoCommoditiesTooltip();
                                    };
                                    break;
                                case STATE_OPEN:
                                    if (this.isUpgradePossible()){
                                        _local1 = ZLoc.t("Dialogs", "UpgradeToolTip");
                                    } else {
                                        if (((this.canCountUpgradeActions()) && (this.canShowUpgradeToolTips()))){
                                            _local1 = ZLoc.t("Main", "UpgradeCallToAction");
                                        };
                                    };
                                case STATE_OPEN_HARVESTABLE:
                                    break;
                                case STATE_CLOSED_HARVESTABLE:
                                    if (Global.player.checkEnergy(-(harvestingDefinition.harvestEnergyCost), false)){
                                        _local1 = ZLoc.t("Main", "BusinessIsHarvestableNoAmount");
                                    } else {
                                        _local1 = ZLoc.t("Main", "NeedEnergy", {amount:harvestingDefinition.harvestEnergyCost});
                                    };
                                    break;
                            };
                        };
                    };
                };
            };
            return (_local1);
        }
        override public function onUpdate(_arg1:Number):void{
            super.onUpdate(_arg1);
            if (this.m_crowdManager){
                this.m_crowdManager.onUpdate(_arg1);
            };
        }
        override public function onPlayAction():void{
            Global.world.citySim.businessVisitBatchManager.onBusinessAction();
            if (this.isUxLockedByQuests){
                displayStatus(ZLoc.t("Main", "QuestUXLocked"));
                return;
            };
            if ((((((m_visitReplayLock > 0)) || (isPendingOrder))) || (Global.isVisiting()))){
                return;
            };
            if (isNeedingRoad){
                super.enterMoveMode();
                return;
            };
            m_actionMode = PLAY_ACTION;
            super.onPlayAction();
            if (((!(hasValidId())) || (isLocked()))){
                showObjectBusy();
                return;
            };
            var _local1:String = getState();
            var _local2:Boolean;
            if (this.isFranchiseSupplied()){
                this.m_shockwaveComplete = false;
                removeStagePickEffect();
                Global.world.citySim.pickupManager.enqueue("NPC_businessPickup", this);
                StatsManager.social(StatsCounterType.FRANCHISES, this.getBusinessOwner(), "accept_sale", m_id.toString());
                return;
            };
            switch (m_state){
                case STATE_CLOSED:
                    if (Global.player.commodities.getAddedCount(this.commodities) >= harvestingDefinition.commodityReq){
                        this.m_isDelivering = true;
                        removeStagePickEffect();
                        Global.world.citySim.pickupManager.enqueue("NPC_businessPickup", this);
                    } else {
                        this.m_isDelivering = false;
                        ResourceExplanationDialog.show(ResourceExplanationDialog.TYPE_NOT_ENOUGH_GOODS, true);
                    };
                    break;
                case STATE_CLOSED_HARVESTABLE:
                    if (this.checkLootable()){
                        _local2 = true;
                    };
                    break;
                case STATE_OPEN:
                    if (((this.canCountUpgradeActions()) && (this.canShowUpgradeToolTips()))){
                        this.m_upgradeDialog = UI.displayBusinessUpgradesDialog(this, this.isUpgradePossible, this.finishUpgradeCallback, this.buyUpgradeCallback);
                        this.m_upgradeDialog.addEventListener(Event.CLOSE, this.removeBusinessUpgradesDialog, false, 0, true);
                    };
                case STATE_OPEN_HARVESTABLE:
                    break;
            };
            if (_local2){
                if (this.m_shockwaveActive){
                    return;
                };
                if (Global.player.checkEnergy(-(harvestingDefinition.harvestEnergyCost))){
                    removeStagePickEffect();
                    Global.world.citySim.pickupManager.enqueue("NPC_businessPickup", this);
                } else {
                    displayStatus(ZLoc.t("Main", "NotEnoughEnergyRed"));
                };
            };
        }
        override public function onVisitPlayAction():void{
            if (((isNeedingRoad) || (isPendingOrder))){
                return;
            };
            m_actionMode = VISIT_PLAY_ACTION;
            m_numVisitorInteractions++;
            this.doTourBus();
            trackVisitAction(TrackedActionType.SENT_BUS);
            NeighborVisitManager.setVisitFlag(NeighborVisitManager.VISIT_TOURBUS);
        }
        override public function onVisitReplayAction(_arg1:TRedeemVisitorHelpAction):Number{
            var _local2:Number = super.onVisitReplayAction(null);
            GameTransactionManager.addTransaction(_arg1);
            m_doobersArray = Global.player.processRandomModifiers(m_item, this, true, m_secureRands);
            Global.world.dooberManager.createBatchDoobers(m_doobersArray, m_item, m_position.x, m_position.y);
            this.doTourBus();
            if (this.canCountUpgradeActions()){
                this.incrementUpgradeActionCount();
            };
            return (_local2);
        }
        protected function unloadTourists():void{
            Global.world.citySim.npcManager.createBusinessPeepsWaiting(this, 3);
        }
        protected function doTourBus():void{
            var loopsound:* = null;
            var rep:* = 0;
            var coins:* = 0;
            lockForReplay();
            Sounds.play("tourbus_start");
            loopsound = Sounds.play("tourbus_engine_loop", 0, Sounds.LOOPING);
            intTourBusNPCCount++;
            removeStagePickEffect();
            var nearRoad:* = Global.world.citySim.roadManager.findClosestRoad(getPosition());
            if (!nearRoad){
                if (Global.isVisiting()){
                    rep = Global.gameSettings.getInt("friendVisitBusinessRepGain", 1);
                    coins = Global.gameSettings.getNumber("friendHelpDefaultCoinReward", 10);
                    finalizeAndAwardVisitorHelp(VisitorHelpType.BUSINESS_SEND_TOUR, rep, coins);
                };
                return;
            };
            var startRoad:* = Global.world.citySim.roadManager.findRandomRoadOnScreen(nearRoad);
            this.m_tourBus = new TourBus(TOUR_BUS, false);
            this.m_tourBus.setPosition(startRoad.getHotspot().x, startRoad.getHotspot().y);
            Global.world.citySim.npcManager.addVehicle(this.m_tourBus);
            var actions:* = this.m_tourBus.getStateMachine();
            actions.removeAllStates();
            actions.addActions(new ActionAnimationEffect(this.m_tourBus, EffectType.VEHICLE_POOF), new ActionNavigate(this.m_tourBus, this, startRoad).setPathType(RoadManager.PATH_ROAD_ONLY), new ActionFn(this.m_tourBus, Curry.curry(function (_arg1:Business):void{
                _arg1.m_tourBus.full = false;
                _arg1.unloadTourists();
            }, this)), new ActionFn(this.m_tourBus, function ():void{
                Sounds.stop(loopsound);
                Sounds.play("tourbus_honk");
                Sounds.play("peopleMoveIn");
            }), new ActionProgressBar(this.m_tourBus, this, ZLoc.t("Main", "UnloadingTourists")), new ActionFn(this.m_tourBus, function ():void{
                var _local1:*;
                var _local2:*;
                if (Global.isVisiting()){
                    _local1 = Global.gameSettings.getInt("friendVisitBusinessRepGain", 1);
                    _local2 = Global.gameSettings.getNumber("friendHelpDefaultCoinReward", 10);
                    finalizeAndAwardVisitorHelp(VisitorHelpType.BUSINESS_SEND_TOUR, _local1, _local2);
                    if (((canCountUpgradeActions()) && (canShowUpgradeToolTips()))){
                        displayStatus(ZLoc.t("Main", "UpgradeHelp"), "", EmbeddedArt.lightishBlueTextColor);
                    };
                };
                Sounds.play("tourbus_start");
                loopsound = Sounds.play("tourbus_engine_loop", 0, Sounds.LOOPING);
                unlockForReplay();
            }), new ActionNavigate(this.m_tourBus, startRoad, this), new ActionFn(this.m_tourBus, function ():void{
                Sounds.stop(loopsound);
                Sounds.play("tourbus_stop");
            }), new ActionDie(this.m_tourBus));
            displayStatus(ZLoc.t("Main", "SendingTourists"));
        }
        public function performVisit(_arg1:Peep):void{
            var _local2 = (_arg1.spawnSource == Peep.SOURCE_HOUSE);
            var _local3:int = (_local2) ? 1 : 0;
            var _local4:int = (_local2) ? 0 : 1;
            if (((Global.isVisiting()) || (Global.isTransitioningWorld))){
                return;
            };
            if ((((m_state == STATE_CLOSED)) || ((m_state == STATE_CLOSED_HARVESTABLE)))){
                return;
            };
            if (this.m_visits == this.maxVisits){
                return;
            };
            var _local5:int = ((_local3 * Global.gameSettings.getInt("cruiseShipTownieMultiplier", 1)) + (_local4 * Global.gameSettings.getInt("cruiseShipTouristMultiplier", 2)));
            var _local6 = (this.m_visits < this.maxVisits);
            if (_local6){
                this.m_visits = Math.min((this.m_visits + _local5), this.maxVisits);
                Global.world.citySim.businessVisitBatchManager.addVisit(this, _local3, _local4);
            };
            if (this.m_visits == this.maxVisits){
                this.closeBusiness();
                this.makeHarvestable();
            };
        }
        override public function isVisitorInteractable():Boolean{
            if (((isNeedingRoad) || (isPendingOrder))){
                return (false);
            };
            return (true);
        }
        public function startCollecting():void{
            if (this.m_crowdManager.findNpcsInRange().length <= 0){
                displayStatus(ZLoc.t("Main", "BusinessNoCustomers"));
                this.m_noShockwaveHits = true;
                return;
            };
            if (this.isFranchiseSupplied()){
                this.m_shockwaveActive = true;
                UI.popupLock();
                this.m_crowdManager.performFranchiseShockwave();
                this.m_noShockwaveHits = false;
            };
        }
        public function onWaveFinished():void{
            this.m_shockwaveActive = false;
            this.m_shockwaveComplete = true;
            UI.popupUnlock();
            if (this.harvest()){
                this.doHarvestDropOff();
            };
        }
        override public function harvest():Boolean{
            var _local1:int;
            var _local3:Number;
            var _local4:Number;
            m_isHarvesting = false;
            if (((((!(this.m_shockwaveActive)) && (!(this.m_shockwaveComplete)))) && (this.isFranchiseSupplied()))){
                this.startCollecting();
                return (false);
            };
            if (this.isNeverOpened()){
                this.doGrandOpeningAnimation();
                trackAction(TrackedActionType.FIRST_PLANT);
            };
            if (this.m_crowdManager.npcsCaptured){
                _local1 = Math.min(this.m_crowdManager.npcsCaptured, Global.gameSettings.getInt("maxShockwaveHits", 10));
            } else {
                if (this.m_noShockwaveHits){
                    return (false);
                };
                _local1 = this.m_visits;
            };
            harvestCounter++;
            var _local2:int;
            if (!this.isFranchiseSupplied()){
                _local3 = (_local1 * getSupplyBonus());
                m_doobersArray = this.makeDoobers(_local3);
                clearSupply();
                this.m_visits = 0;
                this.makeNonHarvestable();
                this.updateArrow();
                spawnDoobers();
            } else {
                m_doobersArray = this.makeDoobers(_local1);
                _local2 = this.m_friendFranchiseData.commodityLeft;
                this.m_friendFranchiseData.commodityLeft = 0;
                this.updateArrow();
                spawnDoobers();
                _local4 = (this.m_friendFranchiseData.starRating) ? this.m_friendFranchiseData.starRating : 1;
                this.displayStatus(ZLoc.t("Main", "HarvestStars", {
                    count:_local4,
                    star:ZLoc.tk("Items", "bus_star", "", _local4)
                }), null);
                this.countUpgradeActionIfPossible();
            };
            GameTransactionManager.addTransaction(new THarvestBusiness(this, _local1, _local2));
            trackAction(TrackedActionType.HARVEST);
            Global.player.heldEnergy = (Global.player.heldEnergy - m_heldEnergy);
            this.m_cooldownStart = getTimer();
            if (m_highlighted){
                setHighlighted(true);
            };
            BanditManager.processBusinessHarvest(this);
            this.updateEffects();
            return (true);
        }
        override protected function makeDoobers(_arg1:Number=1):Array{
            var _local4:int;
            var _local5:Number;
            var _local6:int;
            var _local2:Dictionary = processBaseDoobers(harvestingDefinition, m_secureRands);
            var _local3:Array = new Array();
            if (!this.isFranchiseSupplied()){
                if (_local2["coin"]){
                    _local4 = Math.ceil((_local2["coin"] * _arg1));
                    _local3.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_COIN, _local4), _local4, this));
                };
                if (_local2["xp"]){
                    _local4 = Math.ceil(_local2["xp"]);
                    _local3.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_XP, _local4), _local4, this));
                };
                if (_local2["energy"]){
                    _local4 = Math.ceil(_local2["energy"]);
                    _local3.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_ENERGY, _local4), _local4, this));
                };
                if (_local2["goods"]){
                    _local4 = Math.ceil(_local2["goods"]);
                    _local3.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_GOODS, _local4), _local4, this));
                };
                if (_local2["collectable"]){
                    _local3.push(new Array(_local2["collectable"], 1, this));
                };
                if (_local2["item"]){
                    _local3.push(new Array(_local2["item"], 1, this));
                };
            } else {
                if (_local2["coin"]){
                    _local5 = this.getRewardScale(this.m_friendFranchiseData.starRating);
                    _local6 = _arg1;
                    _local4 = Math.ceil(((_local2["coin"] * _local6) * _local5));
                    _local3.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_COIN, _local4), _local4, this));
                };
                _local4 = harvestingDefinition.commodityReq;
                _local3.push(new Array(Global.gameSettings.getDooberFromType(Commodities.GOODS_COMMODITY, _local4), _local4, this));
                _local3.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_ENERGY, 1), Global.gameSettings.getInt("recipientEnergy"), this));
            };
            return (_local3);
        }
        private function getRewardScale(_arg1:int):Number{
            if (_arg1 <= 0){
                return (1);
            };
            var _local2:Array = new Array();
            var _local3 = "ratingScale";
            var _local4:int;
            while (_local4 < 5) {
                _local3 = (_local3 + (_local4 + 1).toString());
                _local3 = (_local3 + "Star");
                _local2.push(Global.gameSettings.getNumber(_local3, 1));
                _local3 = "ratingScale";
                _local4++;
            };
            return (_local2[(_arg1 - 1)]);
        }
        override public function doHarvestDropOff(_arg1:Boolean=true):Object{
            if (_arg1){
                displayDelayedResourceChanges();
            };
            return (super.doHarvestDropOff(_arg1));
        }
        public function updateRibbons():void{
            if (((((((((((m_content) || (m_maskBitmap))) || (m_itemImage))) && (!(this.gotRibbons)))) && (this.m_neverOpened))) || (this.needRibbons))){
                if (((((!(this.gotRibbons)) && (hasValidId()))) && (!(isNeedingRoad)))){
                    removeAnimatedEffects();
                    addAnimatedEffect(EffectType.RIBBONS);
                    addAnimatedEffect(EffectType.BALLOONS);
                    this.gotRibbons = true;
                };
                this.needRibbons = true;
            };
        }
        public function energyChanged(_arg1:Number):void{
        }
        public function levelChanged(_arg1:int):void{
        }
        public function commodityChanged(_arg1:int, _arg2:String):void{
            if ((((_arg1 < 1)) && ((Global.player.commodities.getTotalCount() < 1)))){
                this.m_isDelivering = false;
                ResourceExplanationDialog.show(ResourceExplanationDialog.TYPE_NOT_ENOUGH_GOODS);
            };
        }
        public function xpChanged(_arg1:int):void{
        }
        public function goldChanged(_arg1:int):void{
        }
        public function cashChanged(_arg1:int):void{
        }
        override public function getPickupAction():Class{
            if (this.isFranchiseSupplied()){
                return (ActionHarvest);
            };
            switch (m_state){
                case STATE_OPEN_HARVESTABLE:
                case STATE_OPEN:
                    return (ActionHarvest);
                case STATE_CLOSED_HARVESTABLE:
                    return (ActionHarvest);
                case STATE_CLOSED:
                    return (ActionBusinessOpen);
            };
            return (null);
        }
        override public function getHarvestTime():Number{
            switch (m_state){
                case STATE_CLOSED:
                    return (Global.gameSettings.getNumber("actionBarBizOpen"));
                case STATE_OPEN_HARVESTABLE:
                case STATE_CLOSED_HARVESTABLE:
                default:
                    return (Global.gameSettings.getNumber("actionBarBizHarvest"));
            };
        }
        public function getOpenTime():Number{
            return (Global.gameSettings.getNumber("actionBarBizOpen"));
        }
        override public function getActionText():String{
            switch (m_state){
                case STATE_CLOSED:
                    return (ZLoc.t("Main", "BusinessOpening"));
                case STATE_OPEN_HARVESTABLE:
                case STATE_CLOSED_HARVESTABLE:
                default:
                    return (ZLoc.t("Main", "BusinessHarvesting"));
            };
        }
        public function getOpeningText():String{
            return (ZLoc.t("Main", "BusinessOpening"));
        }
        public function openBusiness():void{
            switch (m_state){
                case STATE_CLOSED:
                    setState(STATE_OPEN);
                    break;
                case STATE_CLOSED_HARVESTABLE:
                    setState(STATE_OPEN_HARVESTABLE);
                    break;
            };
        }
        public function closeBusiness():void{
            switch (m_state){
                case STATE_OPEN_HARVESTABLE:
                    setState(STATE_CLOSED_HARVESTABLE);
                    break;
                case STATE_OPEN:
                    setState(STATE_CLOSED);
                    break;
            };
        }
        override public function onSell():void{
            super.onSell();
            if (this.isFranchise()){
                FranchiseViralManager.triggerFranchiseViralFeeds(FranchiseViralManager.VIRAL_REMOVEDBUILDING, this.m_itemName, itemOwner, null, 0, this);
            };
        }
        public function makeHarvestable():void{
            switch (m_state){
                case STATE_OPEN:
                    setState(STATE_OPEN_HARVESTABLE);
                    break;
                case STATE_CLOSED:
                    setState(STATE_CLOSED_HARVESTABLE);
                    break;
            };
        }
        public function makeNonHarvestable():void{
            switch (m_state){
                case STATE_OPEN_HARVESTABLE:
                    setState(STATE_OPEN);
                    break;
                case STATE_CLOSED_HARVESTABLE:
                    setState(STATE_CLOSED);
                    break;
            };
        }
        public function get visits():int{
            return (this.m_visits);
        }
        public function checkLootable():Boolean{
            if ((((this.m_visits == this.maxVisits)) && (Global.player.checkEnergy(-(harvestingDefinition.harvestEnergyCost), true)))){
                return (true);
            };
            if (this.m_visits == this.maxVisits){
                if (!Global.player.checkEnergy(-(harvestingDefinition.harvestEnergyCost))){
                    displayStatus(ZLoc.t("Main", "NotEnoughEnergyRed"));
                };
            };
            return (false);
        }
        override public function deferProgressBarToNPC():Boolean{
            return (false);
        }
        override public function getProgressBarStartFunction():Function{
            var harvestResource:* = null;
            harvestResource = this;
            return (function ():Boolean{
                var _local1:*;
                if (!Global.isVisiting()){
                    if (m_actionMode != VISIT_REPLAY_ACTION){
                        if (isFranchiseSupplied()){
                        } else {
                            switch (m_state){
                                case STATE_OPEN_HARVESTABLE:
                                case STATE_CLOSED_HARVESTABLE:
                                    if (!checkLootable()){
                                        return (false);
                                    };
                                    Sounds.playFromSet(Sounds.SET_HARVEST, harvestResource);
                                    _local1 = harvestingDefinition.harvestEnergyCost;
                                    doEnergyChanges(-(_local1), new Array("energy", "expenditures", "collect_business", harvestingDefinition.name), false);
                                    Global.player.heldEnergy = (Global.player.heldEnergy + _local1);
                                    m_heldEnergy = _local1;
                                    m_isHarvesting = true;
                                    break;
                                case STATE_CLOSED:
                                    if (Global.player.commodities.getAddedCount(commodities) < harvestingDefinition.commodityReq){
                                        m_isDelivering = false;
                                        ResourceExplanationDialog.show(ResourceExplanationDialog.TYPE_NOT_ENOUGH_GOODS, true);
                                        return (false);
                                    };
                                    break;
                            };
                        };
                    } else {
                        Sounds.playFromSet(Sounds.SET_HARVEST, harvestResource);
                    };
                };
                return (true);
            });
        }
        override public function getProgressBarEndFunction():Function{
            if (!Global.isVisiting()){
                if (this.isFranchiseSupplied()){
                    return (Curry.curry(function (_arg1:HarvestableResource):void{
                        if (_arg1.harvest()){
                            _arg1.doHarvestDropOff();
                        };
                    }, this));
                };
                if (m_actionMode != VISIT_REPLAY_ACTION){
                    switch (m_state){
                        case STATE_CLOSED:
                            return (this.openBusiness);
                        case STATE_OPEN:
                        case STATE_OPEN_HARVESTABLE:
                            return (null);
                        case STATE_CLOSED_HARVESTABLE:
                            return (Curry.curry(function (_arg1:HarvestableResource):void{
                                if (_arg1.harvest()){
                                    _arg1.doHarvestDropOff();
                                };
                            }, this));
                    };
                };
            };
            return (null);
        }
        override public function getProgressBarCancelFunction():Function{
            return (function ():void{
                m_isHarvesting = false;
                updateArrow();
                Global.player.heldEnergy = (Global.player.heldEnergy - m_heldEnergy);
            });
        }
        override public function getProgressBarOffset():Point{
            if (this.content){
                return (new Point(0, (this.content.height >> 1)));
            };
            return (new Point(0, 0));
        }
        override protected function getItemImageHotspots(_arg1:Item, _arg2:String, _arg3:int, _arg4:String=""):Vector.<Vector3>{
            return (_arg1.getCachedImageHotspots(DEFAULT_BUSINESS_IMAGE, m_direction, _arg4));
        }
        override public function prepareForStorage():void{
            if (((((this.isOpen()) && (this.canCountUpgradeActions()))) || (this.isHarvestable()))){
                decrementUpgradeActionCount();
            };
            this.closeBusiness();
            if (m_state == STATE_CLOSED_HARVESTABLE){
                setState(STATE_CLOSED);
            };
            this.m_visits = 0;
            super.prepareForStorage();
        }
        override public function warnForStorage():Boolean{
            if (m_state == STATE_CLOSED){
                return (false);
            };
            return (true);
        }
        override public function canCountUpgradeActions():Boolean{
            return (((super.canCountUpgradeActions()) && (Global.player.isEligibleForBusinessUpgrades())));
        }
        override public function canShowUpgradeToolTips():Boolean{
            return (((((Global.player) && (Global.player.getSeenFlag(UPGRADES_FLAG_INTRO)))) || (((Global.questManager) && (Global.questManager.hasSeenQuestIntro(UPGRADE_QUEST_NAME))))));
        }
        override public function canShowAlternativeUpgradeToolTip():Boolean{
            return (((super.canShowAlternativeUpgradeToolTip()) && (Global.player.isEligibleForBusinessUpgrades())));
        }
        public function countUpgradeActionIfPossible():void{
            if (this.canCountUpgradeActions()){
                this.incrementUpgradeActionCount();
            };
        }
        override public function incrementUpgradeActionCount(_arg1:Boolean=true):void{
            var _local5:String;
            var _local6:String;
            var _local7:WelcomeDialog;
            super.incrementUpgradeActionCount();
            if (((!(this.m_upgradeDialog)) && (this.canShowUpgradeToolTips()))){
                this.showUpgradeProgressFloaterText(EmbeddedArt.lightishBlueTextColor);
            };
            var _local2:Number = Number(getItem().upgrade.requirements.getRequirementValue(Requirements.REQUIREMENT_UPGRADE_ACTIONS));
            var _local3:Number = 0.51;
            var _local4:Number = ((_local2 - 2) / _local2);
            if (((((((_arg1) && (!(Global.player.getSeenFlag(UPGRADES_FLAG_HALFWAY))))) && ((getItem().upgrade.getUpgradeActionsProgress(this) >= _local3)))) && ((getItem().upgrade.getUpgradeActionsProgress(this) <= _local4)))){
                Global.player.setSeenFlag(UPGRADES_FLAG_HALFWAY);
                _local5 = ZLoc.t("Dialogs", "UpgradesHalfWay");
                _local6 = ZLoc.t("Dialogs", "UpgradesHalfWay_title");
                _local7 = new WelcomeDialog(_local5, _local6, 0, null, true, "assets/missions/architect_167.png");
                UI.displayPopup(_local7, true, _local6);
                StatsManager.sample(100, StatsCounterType.DIALOG, "businessupgradesui", "halfway_message", getItemName());
            };
            if (((((this.isThisFirstBusinessUpgrade()) && ((getItem().level == 1)))) && ((getItem().upgrade.getUpgradeActionsRemaining(this) == 1)))){
                Global.ui.showTickerMessage(ZLoc.t("Main", "TickerBusinessUpgradesAlmost"), true);
            };
        }
        override public function showUpgradeProgressFloaterText(_arg1:uint=0xFFFFFF):void{
            var total:* = NaN;
            var amount:* = NaN;
            var tempDisplay:* = null;
            var progress:* = NaN;
            var tempSpriteHolder:* = null;
            var tempSpriteWindow:* = null;
            var color:int = _arg1;
            if (this.canCountUpgradeActions()){
                total = Number(this.getItem().upgrade.requirements.getRequirementValue(Requirements.REQUIREMENT_UPGRADE_ACTIONS));
                amount = Math.min(this.upgradeActions.getTotal(), total);
                if (amount < total){
                    tempDisplay = new SimpleProgressBar(EmbeddedArt.darkBlueToolTipColor, EmbeddedArt.UPGRADE_HIGHLIGHT_COLOR, 100, 10, 2, -3);
                    progress = this.getItem().upgrade.getUpgradeActionsProgress(this);
                    tempSpriteHolder = new Sprite();
                    tempSpriteWindow = new JWindow(tempSpriteHolder);
                    tempDisplay.setTitleColor(12443872);
                    tempDisplay.setOutlineColor(0);
                    tempDisplay.setBgAlpha(1);
                    tempDisplay.setOutlineAlpa(0.8);
                    tempDisplay.setFilters([Business.UPGRADE_FLOATER_GLOW]);
                    tempDisplay.setPreferredHeight(50);
                    tempSpriteWindow.setContentPane(tempDisplay);
                    ASwingHelper.prepare(tempDisplay);
                    ASwingHelper.prepare(tempSpriteWindow);
                    tempSpriteWindow.show();
                    tempDisplay.setProgress(progress);
                    tempDisplay.setTitle(String(((("" + amount) + "/") + total)));
                    MovieClipUtil.runWhenOnStage(tempDisplay, Curry.curry(function (_arg1:SimpleProgressBar):void{
                        _arg1.setProgressBarFlash();
                    }, tempDisplay));
                    displayStatusComponent(tempSpriteHolder);
                } else {
                    this.displayStatus(ZLoc.t("Main", "UpgradeReady"), "", color);
                };
            };
        }
        private function isThisFirstBusinessUpgrade():Boolean{
            var _local2:Business;
            var _local1:Array = Global.world.getObjectsByClass(Business);
            for each (_local2 in _local1) {
                if (_local2.getItem().level > this.getItem().level){
                    return (false);
                };
                if (((((!((_local2 == this))) && ((_local2.getItem().level == this.getItem().level)))) && ((_local2.upgradeActions.getTotal() >= this.upgradeActions.getTotal())))){
                    return (false);
                };
            };
            return (true);
        }
        override public function isUpgradePossible():Boolean{
            var _local2:XML;
            var _local3:XML;
            var _local4:ItemImage;
            var _local1:Boolean = super.isUpgradePossible();
            if (_local1 == true){
                _local2 = Global.gameSettings.getEffectByName("fireworks");
                _local3 = _local2.image[0];
                _local4 = new ItemImage(_local3);
                _local4.load();
                Sounds.loadSoundByName("cruise_fireworks");
            };
            return (_local1);
        }
        override public function onUpgrade(_arg1:Item, _arg2:Item, _arg3:Boolean=true):void{
            var upgradeDoobers:* = null;
            var me:* = null;
            var ids:* = null;
            var oldItem:* = _arg1;
            var newItem:* = _arg2;
            var a_sendMechanicTxn:Boolean = _arg3;
            upgradeDoobers = grantUpgradeRewards();
            super.onUpgrade(oldItem, newItem);
            this.m_crowdManager.loadShockWaveSettings(newItem.name);
            this.m_itemName = newItem.name;
            this.resetUpgradeActionCount();
            me = this;
            ids = me.m_upgradeActions.getFriendHelperIds();
            m_defaultUpgradeFinish = function ():void{
                me.m_visits = me.maxVisits;
                closeBusiness();
                makeHarvestable();
                setState(getState());
                if (((!((upgradeDoobers == null))) && ((upgradeDoobers.length > 0)))){
                    Global.world.dooberManager.createBatchDoobers(upgradeDoobers, m_item, m_position.x, m_position.y, true);
                };
                fireZeMissiles();
                if (((!((ids == null))) && ((ids.length > 0)))){
                    TimerUtil.callLater(function ():void{
                        var d:* = new GenericDialog(ZLoc.t("Dialogs", "UpgradesThankFriends"), "", GenericDialogView.TYPE_OK, function (_arg1:GenericPopupEvent):void{
                            var _local2:*;
                            if (_arg1.button == GenericDialogView.YES){
                                _local2 = Global.gameSettings.getString("businessUpgradeFriendReward", "mysterygift_v1");
                                if ((((Global.gameSettings.getItemByName(_local2) == null)) || (!(Global.gameSettings.getItemByName(_local2).giftable)))){
                                    ErrorManager.addError(("Invalid friend gift name: " + _local2));
                                    _local2 = "mysterygift_v1";
                                };
                                StatsManager.sample(100, StatsCounterType.DIALOG, "businessupgradesui", "send_gift", getItemName());
                                UpgradesUtil.redirectToGiftPage(_local2, ids);
                            };
                        });
                        UI.displayPopup(d, true);
                    }, 5000);
                };
            };
            var dataMechanic:* = (MechanicManager.getInstance().getMechanicInstance(this, UpgradeActions.MECHANIC_NAME, MechanicManager.ALL) as IDictionaryDataMechanic);
            if (dataMechanic){
                dataMechanic.clear(a_sendMechanicTxn);
            };
            StatsManager.sample(100, StatsCounterType.GAME_ACTIONS, "business", "upgrade_from", oldItem.name);
            StatsManager.sample(100, StatsCounterType.GAME_ACTIONS, "business", "upgrade_to", newItem.name);
        }
        protected function finishUpgradeCallback(_arg1:Event):void{
            var _local2:String;
            if (this.isUpgradePossible()){
                this.m_upgradeDialog.close();
                upgradeBuildingIfPossible();
            } else {
                StatsManager.sample(100, StatsCounterType.DIALOG, "businessupgradesui", "get_help", getItemName());
                _local2 = ("upgradeHelp.php?wId=" + m_id);
                FrameManager.navigateTo(_local2);
            };
        }
        protected function buyUpgradeCallback():Boolean{
            return (false);
        }
        protected function removeBusinessUpgradesDialog(_arg1:Event):void{
            this.m_upgradeDialog = null;
        }
        protected function onUpgradeGateSuccess():void{
            this.upgradeBuildingIfPossible();
        }
        private function fireZeMissiles(_arg1:Event=null):void{
            var m_biz:* = null;
            var e = _arg1;
            Sounds.play("cruise_fireworks");
            m_biz = this;
            MapResourceEffectFactory.createEffect(m_biz, EffectType.FIREWORK_BALLOONS);
            TimerUtil.callLater(function ():void{
                MapResourceEffectFactory.createEffect(m_biz, EffectType.FIREWORK_BALLOONS);
            }, 300);
            TimerUtil.callLater(function ():void{
                MapResourceEffectFactory.createEffect(m_biz, EffectType.FIREWORK_BALLOONS);
            }, 500);
            TimerUtil.callLater(function ():void{
                MapResourceEffectFactory.createEffect(m_biz, EffectType.FIREWORK_BALLOONS);
            }, 700);
        }

    }
}//package Classes 
